package main.java.indi.zyj.c150.greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class _04_NoMergingInterval {


    public int eraseOverlapIntervals(int[][] intervals) {



        Arrays.sort(intervals, (int[] interval1, int[] interval2) -> interval1[1] - interval2[1]);

        int n = intervals.length;
        int right = intervals[0][1];
        int ans = 1;
        for (int i = 1; i < n; ++i) {
            if (intervals[i][0] >= right) {
                ++ans;
                right = intervals[i][1];
            }
        }
        return n - ans;
    }
}
